//
//  JHSSickDesprationController.m
//  JHSSweep
//
//  Created by chenWei on 2017/3/24.
//  Copyright © 2017年 JHDS. All rights reserved.
//

#import "JHSSickDesprationController.h"

@interface JHSSickDesprationController ()
//存储症状名的数组
@property (nonatomic, strong) NSArray *arr;

//保存选中的症状名的数组
@property (nonatomic, strong) NSMutableArray *sickDescriptionArrM;





@end

@implementation JHSSickDesprationController

- (void)viewDidLoad {
    [super viewDidLoad];
    //实例化数组
    _arr = [NSArray array];
    _sickDescriptionArrM = [NSMutableArray array];
    
    //注册
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    
    //加载数据
    _arr = [self loadData];
    
    
    
}

#pragma mark - 代理方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (![_sickDescriptionArrM containsObject:_arr[indexPath.row]]) {
        
        [_sickDescriptionArrM addObject:_arr[indexPath.row]];
    }
    //获取当前cell
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    
    UIButton *btn = [[UIButton alloc]init];
    [btn setImage:[UIImage imageNamed:@"login_protocol"] forState:UIControlStateNormal];
    [cell.contentView addSubview:btn];
    btn.frame = CGRectMake(330, 10, 30, 30);
    
}





//MARK:1- 点击确定出栈
- (IBAction)makeSure:(UIBarButtonItem *)sender {
    
    //把病症描述名数组传过去
    if ([self.delegate respondsToSelector:@selector(sickDesprationController: andNSickDespNameArr:)]) {
        
        [self.delegate sickDesprationController:self andNSickDespNameArr:_sickDescriptionArrM];
        
    }
    
    [self.navigationController popViewControllerAnimated:YES];
    
}






#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return 7;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    
    cell.textLabel.text = _arr[indexPath.row];
    
//    cell.accessoryType = UITableViewCellAccessoryCheckmark;
    
//    cell.editingAccessoryType = UITableViewCellAccessoryNone;
    
    return cell;
}

//加载数据
- (NSArray *)loadData
{
    NSArray *arr = [NSArray arrayWithContentsOfURL:[[NSBundle mainBundle]URLForResource:@"Property List.plist" withExtension:nil]];
    
    return arr;
}







@end
